<?php

namespace frontend\models;

use Yii;
use yii\db\Expression;

/**
 * This is the model class for table "news".
 *
 * @property int $id
 * @property string $title
 * @property string $alias
 * @property string $description
 * @property string $prev_img
 * @property string $date_public
 * @property string $content
 * @property int $id_parent_department
 *
 * @property Department $parentDepartment
 */
class News extends \yii\db\ActiveRecord
{
    const BUCKET_NAME = 'ogikm-img-news';

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'news';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id_info_chanel'], 'integer'],
            [['date_public'], 'safe'],
            [['content'], 'string'],
            [['content', 'id_info_chanel', 'date_public'], 'required'],
            [['prev_img'], 'string', 'max' => 45],
            [['gallery_img'], 'string', 'max' => 512],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'prev_img' => 'Изображение для обложки',
            'date_public' => 'Дата публикации',
            'content' => 'Содержание',
            'id_info_chanel' => 'Информационный канал',
            'gallery_img' => 'Галерея',
        ];
    }

    public function getInfoChanel()
    {
        return $this->hasOne(InfoChanel::className(), ['id' => 'id_info_chanel']);
    }
}
